package cn.jbolt.ec.log;

import cn.jbolt.base.JBoltBaseService;
import cn.jbolt.common.model.BecRetailerCommodity;
import cn.jbolt.common.model.BecRetailerStockChange;
import com.jfinal.kit.Kv;
import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Page;

public class StockLogService extends JBoltBaseService<BecRetailerStockChange> {
    private BecRetailerStockChange dao = new BecRetailerStockChange().dao();
    @Override
    protected BecRetailerStockChange dao() {
        return dao;
    }


    public Page<BecRetailerStockChange> paginate_stock_Log(int pageNumber, int pageSize, String keywords,
                                                           Integer changeTime){

        long t1=System.currentTimeMillis();
        Kv kv = Kv.by("table",table());
        if (keywords!=null&&!keywords.equals("")){
            BecRetailerCommodity becRetailerCommodity1 = new BecRetailerCommodity();
            BecRetailerCommodity becRetailerCommodity = becRetailerCommodity1.dao().findFirst("select * from bec_retailer_commodity where name like ?","%"+keywords+"%");
            if (becRetailerCommodity!=null){
                kv.setIfNotNull("commodityId",becRetailerCommodity.getId());
            }
            else
            {
                kv.setIfNotNull("commodityId",0);
            }
        }


        if (changeTime!=null)
        {
            long ontime_long = (long)changeTime;
            long t2=t1-(ontime_long*1000*3600*24);
            kv.setIfNotNull("changeTime",t2);
        }


        return dao().paginate(pageNumber,pageSize, Db.getSqlPara("ec.mall.manage.log.select_stock_log",kv));
    }

}
